package com.example.computer_exam_training_sys.controller;

import com.example.computer_exam_training_sys.service.QuestionCommentService;
import com.example.computer_exam_training_sys.service.QuestionCommentVOService;
import com.example.computer_exam_training_sys.vo.QuestionCommentDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/commentVO")
@CrossOrigin
public class questionCommentsVOController {


    @Autowired
    private QuestionCommentVOService questionCommentVOService;

    // 全查询：查询全部
    // 访问路径: http://localhost:8080/commentVO/all
    @GetMapping("/all")
    public List<QuestionCommentDTO> getAllComments() {
        return questionCommentVOService.getAllComments();
    }

    // 条件查询：根据题目ID查询评论
    // 访问路径: http://localhost:8080/commentVO/findbyid/1 {id}
    @GetMapping("/findbyid/{id}")
    public QuestionCommentDTO getCommentById(@PathVariable("id") Integer id) {
        return questionCommentVOService.getCommentById(id);
    }

    // 根据题目ID删除评论
    // 访问路径: http://localhost:8080/commentVO/delbyid/3 {id}
    @DeleteMapping("/delbyid/{id}")
    public int deleteComment(@PathVariable("id") Integer id) {
        return questionCommentVOService.deleteCommentById(id);
    }
}
